import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { ItemData } from "../../../../resource/info/ItemData";
import { SkillRuneComposeStuffItem } from "./SkillRuneComposeStuffItem";
import { RuneSwallowConfig } from "../../../../resource/RuneSwallowConfig";
import { SkillRuneComposeTargetItem } from "./SkillRuneComposeTargetItem";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
import { ObjCreate } from "../../../common/ObjCreate";
import { Language } from "../../../../../../extend/language/Language";
import { GButton } from "../../../../../../com/mui/controls/GButton";
import { _stuffDatas } from "../../../../../../this/_stuffDatas";
import { _data } from "../../../../../../this/_data";
type int = number;
//class SkillRuneComposeAComposition
    
    export  class SkillRuneComposeAComposition /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._places = [new Object /* flash.geom.Point */(-1, 0), new Object /* flash.geom.Point */(180, -3), new Object /* flash.geom.Point */(-15, 146), new Object /* flash.geom.Point */(193, 146), new Object /* flash.geom.Point */(90, 208)];
            this.initView();
            this._btnSwallow.addEventListener(flash.events.MouseEvent.CLICK, this.clickSwallowHandler);
            return;
        }

        /* internal  */clickSwallowHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RuneClickHolySwallowRune, {"stuffs": _stuffDatas, "targetData": _data}));
            return;
        }

        public updateView(arg1: ItemData): void
        {
            var loc1=null;
            var loc6=0;
            var loc7=0;
            var loc8=null;
            if (arg1 == null) 
            {
                this._target.update(null);
                loc6 = 0;
                while (loc6 < this._stuffs.length) 
                {
                    loc1 = this._stuffs[loc6] as SkillRuneComposeStuffItem;
                    loc1.update(null, null);
                    ++loc6;
                }
                return;
            }
            this._data = arg1;
            var loc2=RuneSwallowConfig.instance.getHolyRuneCanSwllowCodes(arg1.itemCode);
            var loc3=loc2.length;
            var loc4=[];
            this._stuffDatas = [];
            var loc5=0;
            while (loc5 < this.MaxSwallowNum) 
            {
                loc1 = this._stuffs[loc5] as SkillRuneComposeStuffItem;
                if (loc5 >= loc3) 
                {
                    loc1.setLock();
                }
                else 
                {
                    loc7 = loc2[loc5];
                    loc8 = new ItemData(loc7);
                    this._stuffDatas.push(loc8);
                    if (!(arg1.runeSwallowCodes == null) && arg1.runeSwallowCodes.indexOf(loc7) >= 0) 
                    {
                        loc1.update(loc8, arg1, true);
                    }
                    else 
                    {
                        loc1.update(loc8, arg1);
                    }
                    loc4[loc5] = loc1.swallowStatus;
                }
                ++loc5;
            }
            if (this.isCanSwallow(loc4)) 
            {
                this._btnSwallow.enabled = true;
                this._btnSwallow.mouseEnabled = true;
            }
            else 
            {
                this._btnSwallow.enabled = false;
                this._btnSwallow.mouseEnabled = false;
            }
            this._target.update(this._data);
            return;
        }

        /* internal  */isCanSwallow(arg1: Array<any>): Boolean
        {
            if (arg1 == null || arg1.length < this.MaxSwallowNum) 
            {
                return false;
            }
            var loc1=true;
            var loc2=false;
            var loc3=0;
            while (loc3 < arg1.length) 
            {
                if (arg1[loc3] != SkillRuneComposeStuffItem.SwallowStatusSwallowed) 
                {
                    loc1 = false;
                }
                if (arg1[loc3] == SkillRuneComposeStuffItem.SwallowStatusHaveNo) 
                {
                    loc2 = true;
                }
                ++loc3;
            }
            if (loc1) 
            {
                return false;
            }
            if (loc2) 
            {
                return false;
            }
            return true;
        }

        /* internal  */initView(): void
        {
            var loc3=null;
            var loc4=null;
            this._stuffs = [];
            var loc1=0;
            while (loc1 < this.MaxSwallowNum) 
            {
                loc3 = this._places[loc1];
                (loc4 = new SkillRuneComposeStuffItem()).x = loc3.x;
                loc4.y = loc3.y;
                this.addChild(loc4);
                this._stuffs.push(loc4);
                ++loc1;
            }
            this._target = new SkillRuneComposeTargetItem();
            this._target.x = 79;
            this._target.y = 112;
            this.addChild(this._target);
            var loc2=new GTextFiled();
            this._btnSwallow = ObjCreate.createGButton("", 77, 266, 65, 24, this, "ButtonRed");
            loc2.htmlText = Language.getString(80073);
            this._btnSwallow.label = loc2.text;
            return;
        }

        /* internal */ /* const */MaxSwallowNum: int=2;

        /* internal */ /* var */_data: ItemData;

        /* internal */ /* var */_stuffs: Array<any>;

        /* internal */ /* var */_target: SkillRuneComposeTargetItem;

        /* internal */ /* var */_places: Array<any>;

        /* internal */ /* var */_btnSwallow: GButton;

        /* internal */ /* var */_stuffDatas: Array<any>;
    }
